Package com. rnett. plugin. ir
The com.rnett.plugin.ir
package contains a number of utilities for working with IR. This includes basic utilities such as CompilerConfiguration.messageCollector
, IrClass.addAnonymousInitializer
, IrType.raiseTo
, and IrClass.typeWith(List<IrTypeArgument>)
, all of which are available as extension functions.
Many utilities require a IrPluginContext
, so in lieu of multiple receivers, they are put in HasContext
which has a val context: IrPluginContext
. It can be easily implemented by IrElementTransformer
s. Of special note are the IrBuilderWithScope.buildLambda
and lambdaArgument
functions.
KnowsCurrentFile
is a similar interface, but requires a IrFile
and provides extensions for getting message locations from IrElement
s using said file.
Both of these are implemented by IrTransformer
, which is usable as a replacement for IrElementTransformerVoid
or IrElementTransformerVoidWithContext
. In addition to implementing IrElementTransformerVoidWithContext
, KnowsCurrentFile
, and HasContext
, it modifies the file transformer so that new declarations can be added to the current file without running into ConcurrentModificationException
(it does so by running transforms on a copy of the declaration list, and then on newly added declarations until no more are added).
Types
Remap references to functions. Returning null
will deep copy the symbol.
A bunch of things using context that should mostly be moved to multiple receivers
Utility methods for working with a MessageCollector when the current file is available
A symbol remapper that only replaces references to symbols. Returning null
will deep copy the symbol.
A list of symbol replacements, providing a ReferenceRemapper.
Remap value symbols. If given a IrVariableSymbol, must return a IrVariableSymbol. Returning null
will deep copy the symbol.
Functions
Deep copy and replace references to values.
Deep copy and replace references to symbols
Deep copy and replace references
Deep copy and replace references to values
IrExprBody on JS causes issues: (https://youtrack.jetbrains.com/issue/KT-49561).
Set the type arguments of the call. If substitute is true
and this is an IrCall, calls substituteTypeParams.
Gets the lowest superclass or this that matches the predicate. Helpful for discovering the type parameters of supertypes.
Gets the lowest superclass or this that has the given classifier. Helpful for discovering the type parameters of supertypes.
Gets the lowest superclass or this that matches the predicate, or null if none do. Helpful for discovering the type parameters of supertypes.
Build a list of symbol replacements
Substitute the set type parameters into the return type.
Get the supertypes of a type, substituting type parameters for their values where known and not *
.
Get the arguments of an IrCall by their parameter names
Set the type arguments of the call. If substitute is true
and this is an IrCall, calls substituteTypeParams.